package com.lmj.learnspringboot.controller;

import com.lmj.learnspringboot.annotation.ResponseResult;
import com.lmj.learnspringboot.model.result.Result;
import com.lmj.learnspringboot.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: lmj
 * @version: GlobalHandlerController.java lmj v1.0 2021/8/8 01:55
 */

@Slf4j
@RestController
@ResponseResult
@RequiredArgsConstructor
public class GlobalHandlerController {

    private final UserService userService;

    @GetMapping("/test/map")
    public Map<String, Object> test() {
        HashMap<String, Object> data = new HashMap<>(3);
        data.put("info", "测试成功");
        return data;
    }

    @PostMapping("/test/string")
    public String testString() {
        return "测试成功";
    }

    @PostMapping("/test/exception")
    public String testException() {
        int i = 1 / 0;
        return "测试成功";
    }

    @PostMapping("/test/userInfo/{name}")
    public Result getUserInfo(@PathVariable String name) {
        return userService.getUserInfo(name);
    }
}
